Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald\src\datatype\payload_data.cpp
Line
Count
Source (jump to first uncovered line)
1
//  Copyright 2020-2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#include "herald/datatype/payload_data.h"
6
#include "herald/datatype/base64_string.h"
7
8
#include <algorithm>
9
#include <string>
10
11
namespace herald {
12
namespace datatype {
13
14
PayloadData::PayloadData()
15
  : Data()
16
129
{
17
129
  ;
18
129
}
19
20
PayloadData::PayloadData(const Data& from)
21
  : Data(from)
22
1
{
23
1
  ;
24
1
}
25
26
PayloadData::PayloadData(const std::byte* data, std::size_t length)
27
  : Data(data,length)
28
1
{
29
1
  ;
30
1
}
31
32
PayloadData::PayloadData(std::byte repeating, std::size_t count)
33
  : Data(repeating,count)
34
11
{
35
11
  ;
36
11
}
37
38
std::string
39
0
PayloadData::shortName() const {
40
0
  if (size() == 0) {
41
0
    return "";
42
0
  }
43
0
  if (!(size() > 3)) {
44
0
    return Base64String::encode(*this).encoded();
45
0
  }
46
0
  const Data suffix = subdata(3, size() - 3);
47
0
  Base64String base64EncodedString = Base64String::encode(suffix);
48
0
  std::string asString = base64EncodedString.encoded();
49
0
  return asString.substr((std::size_t)0, std::min((std::size_t)6, asString.length())); // TODO figure out why we trim 6 chars? What if we don't have 6 chars???
50
0
}
51
52
std::string
53
0
PayloadData::toString() const {
54
0
  return shortName();
55
0
}
56
57
} // end namespace
58
} // end namespace